package com.hopu.v1.controller.front.question;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hopu.v1.pojo.common.R;
import com.hopu.v1.pojo.question.QuestionsComments;
import com.hopu.v1.service.front.question.QuestionsCommentsService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * 我的评论
 */
@RestController
@RequestMapping("/api/v1/front/questionsComment")
public class FQuestionsCommentController {
    @Resource
    private QuestionsCommentsService questionsCommentsService;

    /**
     * 根据学生id查评论
     *
     * @param studentId
     * @return
     */
    @GetMapping
    public R getQuestionsComments(Page<QuestionsComments> page, String studentId) {
        return R.ok(questionsCommentsService.getQuestionCommentByStudentId(page,studentId));
    }


    /**
     * 查看所有评论
     * @param questionId
     * @return
     */
    @GetMapping("showAllComments")
    public R showAllComments(String questionId,String studentId){
        System.out.println(studentId);
        return R.ok(questionsCommentsService.getCommentContentByQuestionId(studentId,questionId));
    }


    /**
     * 回复评论
     * @param questionsComments
     * @return
     */
    @PostMapping
    public R addComment(@RequestBody QuestionsComments questionsComments){
        System.out.println(questionsComments);
        return R.ok("评论成功",questionsCommentsService.save(questionsComments));
    }

    /***
     * 删除评论
     * @param commentId
     * @return
     */
    @DeleteMapping
    public R deleteComment(String commentId){
       return R.ok(questionsCommentsService.removeById(commentId));
    }
}
